﻿using BasicInformationCommon.API.BasicInformationCommons.DropDownCommon.CreditRatingRead;
using ERPSystem.Common.Domains.CustomerProfileCommon;
using ERPSystem.Common.Domains.Material;
using ERPSystem.Common.DTO;
using ERPSystem.Common.Infrastructure.IRepository;
using MediatR;

namespace BasicInformationCommon.API.BasicInformationCommons.DropDownCommon.MaterialRead
{
    public class MaterialReadHandler : IRequestHandler<MaterialReadCommand, Result>
    {
        private readonly IBaseRepository<MaterialCascade> _materialCascadeRepository;

        public MaterialReadHandler(IBaseRepository<MaterialCascade> materialCascadeRepository)
        {
            _materialCascadeRepository = materialCascadeRepository;
        }

        public async Task<Result> Handle(MaterialReadCommand request, CancellationToken cancellationToken)
        {
            var result = new Result();
            try
            {
                var materialCascadeRepository = await (await _materialCascadeRepository.GetAll()).ToListAsync();
                result.Data = materialCascadeRepository;
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
